package com.wenhao.binalifeng;

import java.util.*;

/**
 * @author Wenhao Tong
 * @create 2021-09-01 17:14
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] split = s.split(",");
        List<Integer> list = new ArrayList<>();
        for (int i = 0;i < split.length;i++) {
            list.add(Integer.parseInt(split[i]));
        }
        Collections.sort(list);
        int x = -1;
        int result = 0;
        for (Integer i : list) {
            if (x == -1) {
                x = i;
            } else {
                if (i >= x) {
                    x = i;
                } else {
                    result += x - i;
                }
            }
            x++;
        }
        System.out.println(result);
    }
}
